//
//  TuiJianView.m
//  ShopDemo
//
//  Created by Sunshine on 2018/9/4.
//  Copyright © 2018年 飞扬的青春. All rights reserved.
//

#import "TuiJianView.h"
#import "FirstOneCollectionCell.h"
@implementation TuiJianView



- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UILabel *leftlabe = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 40*kJLXWidthScale)];
        leftlabe.text = @"为你推荐";
        leftlabe.font = [UIFont systemFontOfSize:18*kJLXWidthScale];
        leftlabe.textColor = [UIColor redColor];
        leftlabe.textAlignment = NSTextAlignmentCenter;
        self.centerlab = leftlabe;
        [self addSubview:leftlabe];
        [self creatCollectionviewMethod];
    }
    return self;
}


-(void)creatCollectionviewMethod{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
    self.listCollectionview = [[ UICollectionView alloc ] initWithFrame:CGRectMake(0, 40*kJLXWidthScale, kScreenWidth, self.height-40*kJLXWidthScale) collectionViewLayout :layout];
    [self addSubview:self.listCollectionview];
    if (kScreenHeight == 812) {
        self.listCollectionview.sd_layout
        .bottomSpaceToView(self, 34);
    }
    self.listCollectionview.delegate = self;
    self.listCollectionview.dataSource = self;
    self.listCollectionview.backgroundColor = [UIColor whiteColor];
    [self.listCollectionview registerClass :[ FirstOneCollectionCell class ] forCellWithReuseIdentifier : @"twocell" ];
}


#pragma mark--------------------UICollectionViewDelegateFlowLayout,UICollectionViewDelegate, UICollectionViewDataSource
//cell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataArray.count;
}
//
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    FirstOneCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"twocell" forIndexPath:indexPath];
    NSDictionary *dic = self.dataArray[indexPath.row];
    cell.titImageview.frame = CGRectMake(0, 0,kScreenWidth / 2-2-40*kJLXWidthScale, kScreenWidth / 2-2-40*kJLXWidthScale);
     cell.titImageview.center = cell.contentView.center;
    NSURL *url = [NSURL URLWithString:[MethodClass returnUrlSetStrWSDLURL:dic[@"GOODS_PIC"]]];
    [cell.titImageview sd_setImageWithURL:url];
    cell.titlab.text = [NSString stringWithFormat:@"%@",dic[@"GOODS_NAME"]];
    cell.pricelab.textColor = [UIColor orangeColor];
    cell.pricelab.text = [NSString stringWithFormat:@"￥%@",dic[@"GOODS_MINPRICE"]];
    return cell;
}
#pragma mark-------------------布局代理
//设置每个cell的宽和高
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(kScreenWidth / 2-2, kScreenWidth / 2-2);
}
//设置分区缩进
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(8*kJLXWidthScale, 0, 8*kJLXWidthScale, 0);
}
//设置每个分区之间最小的行间距和列间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 5*kJLXWidthScale;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 1;
}
#pragma mark--------------------------cell点击事件
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
        self.detailBlock(self.dataArray[indexPath.row]);
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/




@end
